package edu.sctu.zhoudie.mouth201506.day20150615;

import java.io.*;

/**
 * Created by user08 on 2015/6/15.
 */
public class MyBufferReader {
    public void buffer() {
        char c1[], c2[];
        String str;
        CharArrayReader cin;
        CharArrayWriter cout;
        InputStreamReader sin = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(sin);//将键盘上输入的数据放入到BufferReader中去
        OutputStreamWriter out = new OutputStreamWriter(System.out);
        try {
        System.out.println("请输入一个字符串，按enter键结束 ");
            str =in.readLine(); //读入字符串
            c1 = str.toCharArray();//将字符串转换成字符数组
            cin= new CharArrayReader(c1);//创建对象，并与C1绑定
            cout= new CharArrayWriter();//读cin的对象到cout中去
            while (cin.ready())
            {
                cout.write(cin.read());//读cin中的数据到cout中去，读/写指针后移一个字符位置

            }
            System.out.print("c2=");
            c2= cout.toCharArray();
            System.out.println(new String(c2));
            System.out.println("将cout中的对象数据写入out的对象中，并输出：");
            cout.writeTo(out);
            out.flush();
        } catch (IOException e) {
            System.out.println("IO错误!");
        }
    }
}
